<?php
    namespace lib\core;
    
    class error{
        
        public static function register(){
            
            set_error_handler([__CLASS__, 'appError']);
            set_exception_handler([__CLASS__, 'appException']);
            register_shutdown_function([__CLASS__, 'appShutdown']);
        }
        
        public static function appError($type, $message, $file, $line){
            
            switch ($type) {
                case E_ERROR:
                    echo "时间: ".date('Y-m-d H:i:s')."发生 ERROR 错误: " . $type . ":" . $message . " in " . $file . " on " . $line . " line . \r\n";
                    break;
            
                case E_WARNING:
                    echo "时间: ".date('Y-m-d H:i:s')."发生 WARNING 错误: " . $type . ":" . $message . " in " . $file . " on " . $line . " line . \r\n";
                    break;
            
                case E_NOTICE:
                    echo "时间: ".date('Y-m-d H:i:s')."发生 NOTICE 错误: " . $type . ":" . $message . " in " . $file . " on " . $line . " line . \r\n";
                    break;
            
                default:
                    echo "Unknown error type: [$type] $message \r\n";
                    break;
            }
        }
        
        public static function appException($exception){
            
            /**
             * 用法
             * throw new \Exception("error...");
             */
            return "<b>Exception: " . $exception->getMessage()  . '</b>';
            //...
        }
        
        public static function appShutdown(){

            //...
        }
    }